﻿@{
    Layout = "_LayoutAdmin";
}

@model IReadOnlyList<Moonglade.Model.PostSegment>
@section scripts{
    <script>
        $(function () {
            $(".btn-delete").click(function () {
                var cfm = confirm("Delete Confirmation?");
                if (cfm) {
                    deletePost($(this).data("postid"));
                }
            });

            $(".btn-restore").click(function () {
                restorePost($(this).data("postid"));
            });
        });

        function deletePost(postid) {
            $("#span-processing-" + postid).show();
            ajaxPostWithCSRFToken("delete-from-recycle", { postid: postid }, function (data) {
                $("#tr-" + data).hide();
            });
        }

        function restorePost(postid) {
            $("#span-processing-" + postid).show();
            ajaxPostWithCSRFToken("restore", { postid: postid }, function (data) {
                $("#tr-" + data).hide();
            });
        }
    </script>
}
<partial name="_PostManageHeader" />

<a asp-controller="Post" asp-action="EmptyRecycleBin" class="btn btn-outline-danger">
    <span class="icon-bin"></span>
    @Localizer["Empty Recycle Bin"]
</a>

@if (Model.Any())
{
    @Html.AntiForgeryToken()
    <table class="table table-bordered mt-3">
        <thead>
            <tr>
                <th>@Localizer["Title"]</th>
                <th>@Localizer["Created"]</th>
                <th>@Localizer["Options"]</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var post in Model.OrderByDescending(p => p.CreateOnUtc))
            {
                <tr id="tr-@post.Id">
                    <td>@post.Title</td>
                    <td class="text-muted">@post.CreateOnUtc.ToString("MM/dd/yyyy HH:mm")</td>
                    <td>
                        <a class="btn btn-sm btn-primary btn-restore" data-postid="@post.Id" href="javascript:;">
                            <span class="icon-undo2"></span> @Localizer["Restore"]
                        </a>
                        <a class="btn btn-danger btn-sm btn-delete" data-postid="@post.Id" href="javascript:;">
                            <span class="icon-bin"></span> @Localizer["Delete"]
                        </a>
                        <span id="span-processing-@post.Id" style="display: none">...</span>
                    </td>
                </tr>
            }
        </tbody>
    </table>
}
else
{
    <partial name="_NoPosts" />
}